package cn.lg.soar.system.general.client;

import cn.lg.soar.common.util.BeanCopier;
import cn.lg.soar.core.annotations.ApiClient;
import cn.lg.soar.system.api.constant.ModuleConst;
import cn.lg.soar.system.api.model.DictDTO;
import cn.lg.soar.system.api.service.IDictApi;
import cn.lg.soar.system.general.model.DictItemVo;
import cn.lg.soar.system.general.service.IDictItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author luguoxiang
 * @date 2022/1/3
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@ApiIgnore
@ApiClient("boot")
@RestController
@RequestMapping(ModuleConst.CLIENT_PATH + "/dict")
public class DictApiClient implements IDictApi {

    @Autowired
    private IDictItemService service;

    private final static BeanCopier<DictItemVo, DictDTO> BEAN_COPIER = BeanCopier.create(DictItemVo.class, DictDTO.class);

    @GetMapping("listByType")
    @Override
    public List<DictDTO> listByType(String type) {
        List<DictItemVo> list = service.listByCode(type);
        return list.stream().map(BEAN_COPIER::convert).collect(Collectors.toList());
    }

}
